<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>找回密码</title>
    <link rel="stylesheet" href="./css/login.css" type="text/css">
</head>
<body>
    <div class="container">
        <h2>找回密码</h2>
        
        <% if (request.getAttribute("errorMessage") != null) { %>
            <div class="message error-message">
                <%= request.getAttribute("errorMessage") %>
            </div>
        <% } %>
        
        <% 
            String currentPassword = (String) request.getAttribute("currentPassword");
            String verifiedUsername = (String) request.getAttribute("verifiedUsername");
            
            if (currentPassword != null && verifiedUsername != null) {
        %>
            <!-- 显示当前密码 -->
            <div class="containerz">
                <h3>验证成功！</h3>
                <p><strong>用户名：</strong><%= verifiedUsername %></p>
                <p><strong>当前密码：</strong></p>
                <div ><%= currentPassword %></div>
                <p style="color: #856404; font-size: 14px; margin-top: 15px;">
                    ⚠️ 请妥善保管您的密码，不要泄露给他人。
                </p>
            </div>
            
            <!-- 修改密码表单 -->
            <div class="message info-message" style="margin-bottom: 20px;">
                您可以选择修改密码，或直接使用当前密码登录。
            </div>
            
            <form action="forgotPassword" method="post">
                <input type="hidden" name="username" value="<%= verifiedUsername %>">
                <input type="hidden" name="action" value="changePassword">
                
                <div class="form-group">
                    <label for="newPassword">新密码:</label>
                    <input type="password" id="newPassword" name="newPassword" required>
                </div>
                
                <div class="form-group">
                    <label for="confirmPassword">确认新密码:</label>
                    <input type="password" id="confirmPassword" name="confirmPassword" required>
                </div>
                
                <div class="button-group">
                    <button type="submit" class="btn">修改密码</button>
                    <a href="login.jsp" class="btn btn-secondary" style="text-decoration: none; text-align: center; line-height: 38px;">直接登录</a>
                </div>
            </form>
            
        <% } else { %>
            <!-- 验证身份表单 -->
            <form action="forgotPassword" method="post" id="verifyForm">
                <input type="hidden" name="action" value="verify">
                
                <div class="form-group">
                    <label for="username">用户名:</label>
                    <input type="text" id="username" name="username" required>
                </div>
                
                <div class="form-group">
                    <label for="securityQuestion">安全问题:</label>
                    <select id="securityQuestion" name="securityQuestion" required>
                        <option value="">请选择安全问题</option>
                        <option value="你父亲的名字是？">你父亲的名字是？</option>
                        <option value="你母亲的名字是？">你母亲的名字是？</option>
                        <option value="你的出生地是？">你的出生地是？</option>
                        <option value="你最喜欢的颜色是？">你最喜欢的颜色是？</option>
                        <option value="你的小学名字是？">你的小学名字是？</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label for="securityAnswer">安全答案:</label>
                    <textarea id="securityAnswer" name="securityAnswer" required></textarea>
                </div>
                
                <button type="submit" class="btn">验证身份</button>
            </form>
        <% } %>
        
        <div class="links">
            <p><a href="login.jsp">返回登录</a> | <a href="register.jsp">注册账户</a></p>
        </div>
    </div>
</body>
</html>

